﻿using System.Linq;
using System.Windows.Controls;

namespace Songhay.Silverlight.BiggestBox.IndexPart.Views.UserControls
{
    using Extensions;

    //TODO: consider adding Validation Summary here.
    public partial class ValidationSample : UserControl
    {
        public ValidationSample()
        {
            InitializeComponent();

            this.Validate.Click += (s, args) =>
            {
                this.FormFields.Children
                    .OfType<StackPanel>()
                    .First().Children
                    .OfType<ComboBox>()
                    .ForEachInEnumerable(
                        cb =>
                            cb.GetBindingExpression(ComboBox.SelectedItemProperty)
                                .UpdateSource());

                this.FormFields.Children
                    .OfType<TextBox>()
                    .ForEachInEnumerable(
                        tb =>
                            tb.GetBindingExpression(TextBox.TextProperty)
                                .UpdateSource());
            };
        }
    }
}
